package com.atguigu.juc.day02.lock;

import java.util.concurrent.TimeUnit;

public class Demo07CannotInterrupt {

    public static void main(String[] args) throws InterruptedException {

        // 1、创建普通对象作为锁对象
        Object lockObj = new Object();

        // 2、创建 A 线程占用锁
        new Thread(()->{
            synchronized (lockObj) {
                while (true) {}
            }
        }, "thread-a").start();

        // 3、创建 B 线程申请锁
        Thread thread = new Thread(() -> {
            synchronized (lockObj) {

            }
        }, "thread-b");

        // 4、启动 B 线程
        thread.start();

        // 5、主线程等待一会儿，尝试打断 B 线程的阻塞状态
        TimeUnit.SECONDS.sleep(5);

        System.out.println("5秒时间到。");

        thread.interrupt();

    }

}
